home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / convert.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  5.6 KB  |  165 lines

  1.     /*
  2.  
  3.     Copyright (C) 2000 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. #ifndef _arts_convert_h
  24. #define _arts_convert_h
  25.  
  26. #include "arts_export.h"
  27.  
  28. /*
  29.  * BC - Status (2002-03-08): conversion functions
  30.  *
  31.  * None of them will be removed or changed, so it is safe to use them in
  32.  * your apps. It is *recommended* (though not necessary) to use the new
  33.  * resampling code (Resampler) where possible.
  34.  */
  35.  
  36. namespace Arts {
  37.  
  38. /*
  39.  * Simple conversion routines. The function names are chosen like
  40.  *
  41.  *   convert_mono_FROM_TO for mono conversions
  42.  *   convert_stereo_FROM_TO for stereo conversions
  43.  *
  44.  * while FROM/TO are
  45.  *
  46.  *      8 for  8bit signed data
  47.  *   16le for 16bit signed little endian
  48.  *  float for float data between -1 and 1
  49.  *
  50.  * and may be prefixed by 2 to indicate that stereo is done with two seperate
  51.  * buffers or i to indicate interleaved stereo (one buffer which contains
  52.  * one sample left, one sample right, one sample left etc.)
  53.  *
  54.  * The parameter speed (for interpolations) is *not* the samplingrate, but
  55.  * a relative value. A speed of 2.0 means "play twice as fast".
  56.  */
  57.  
  58. // upconversions from integer to float
  59. void ARTS_EXPORT convert_mono_8_float(unsigned long samples,
  60.             unsigned char *from, float *to);
  61.  
  62. void ARTS_EXPORT interpolate_mono_8_float(unsigned long samples,
  63.             double startpos, double speed,
  64.             unsigned char *from, float *to);
  65.  
  66. void ARTS_EXPORT convert_mono_16le_float(unsigned long samples,
  67.             unsigned char *from, float *to);
  68.  
  69. void ARTS_EXPORT interpolate_mono_16le_float(unsigned long samples,
  70.             double startpos, double speed,
  71.             unsigned char *from, float *to);
  72.  
  73. void ARTS_EXPORT convert_mono_16be_float(unsigned long samples,
  74.             unsigned char *from, float *to);
  75.  
  76. void ARTS_EXPORT interpolate_mono_16be_float(unsigned long samples,
  77.             double startpos, double speed,
  78.             unsigned char *from, float *to);
  79.  
  80. void ARTS_EXPORT convert_stereo_i8_2float(unsigned long samples,
  81.             unsigned char *from, float *left, float *right);
  82.  
  83. void ARTS_EXPORT interpolate_stereo_i8_2float(unsigned long samples,
  84.             double startpos, double speed,
  85.             unsigned char *from, float *left, float *right);
  86.  
  87. void ARTS_EXPORT convert_stereo_i16le_2float(unsigned long samples,
  88.             unsigned char *from, float *left, float *right);
  89.  
  90. void ARTS_EXPORT interpolate_stereo_i16le_2float(unsigned long samples,
  91.             double startpos, double speed,
  92.             unsigned char *from, float *left, float *right);
  93.  
  94. void ARTS_EXPORT convert_stereo_i16be_2float(unsigned long samples,
  95.             unsigned char *from, float *left, float *right);
  96.  
  97. void ARTS_EXPORT interpolate_stereo_i16be_2float(unsigned long samples,
  98.             double startpos, double speed,
  99.             unsigned char *from, float *left, float *right);
  100.  
  101. void ARTS_EXPORT convert_mono_float_float(unsigned long samples,
  102.             float *from, float *to);
  103.  
  104. void ARTS_EXPORT interpolate_mono_float_float(unsigned long samples,
  105.             double startpos, double speed,
  106.             float *from, float *to);
  107.  
  108. void ARTS_EXPORT convert_stereo_ifloat_2float(unsigned long samples,
  109.             float *from, float *left, float *right);
  110.  
  111. void ARTS_EXPORT interpolate_stereo_ifloat_2float(unsigned long samples,
  112.             double startpos, double speed,
  113.             float *from, float *left, float *right);
  114.  
  115. // downconversions from float to integer
  116. void ARTS_EXPORT convert_mono_float_16le(unsigned long samples,
  117.             float *from, unsigned char *to);
  118.  
  119. void ARTS_EXPORT convert_stereo_2float_i16le(unsigned long samples,
  120.             float *left, float *right, unsigned char *to);
  121.  
  122. void ARTS_EXPORT convert_mono_float_16be(unsigned long samples,
  123.             float *from, unsigned char *to);
  124.  
  125. void ARTS_EXPORT convert_stereo_2float_i16be(unsigned long samples,
  126.             float *left, float *right, unsigned char *to);
  127.  
  128. void ARTS_EXPORT convert_mono_float_8(unsigned long samples,
  129.             float *from, unsigned char *to);
  130.  
  131. void ARTS_EXPORT convert_stereo_2float_i8(unsigned long samples,
  132.             float *left, float *right, unsigned char *to);
  133.  
  134.  
  135. /*
  136.  * This practical routine picks the right conversion routine for given
  137.  * parameters and makes boundary checks
  138.  */
  139.  
  140. // returnvalue: number of samples generated
  141.  
  142. /* formats for unified conversion */
  143. enum {
  144.   uni_convert_u8         = 8,        // unsigned 8 bit
  145.   uni_convert_s16_le     = 16,        // signed 16 bit, little endian
  146.   uni_convert_s16_be     = 17,        // signed 16 bit, big endian
  147.   uni_convert_float_ne   = 0x100    // float, in native size/byteorder
  148. };
  149.  
  150. unsigned long ARTS_EXPORT uni_convert_stereo_2float(
  151.         unsigned long samples,        // number of required samples
  152.         unsigned char *from,        // buffer containing the samples
  153.         unsigned long fromLen,        // length of the buffer
  154.         unsigned int fromChannels,  // channels stored in the buffer
  155.         unsigned int fromBits,        // number of bits per sample
  156.                                     //  (also: uni_convert_ formats given above)
  157.         float *left, float *right,    // output buffers for left and right channel
  158.         double speed,                // speed (2.0 means twice as fast)
  159.         double startposition        // startposition
  160.     );
  161.  
  162. }
  163.  
  164. #endif
  165.